package com.jiguangssp.addemo.act;

import androidx.constraintlayout.widget.ConstraintLayout;

import android.os.Bundle;

import com.jiguangssp.addemo.R;
import com.jiguangssp.addemo.util.Constants;

import xyz.adscope.amps.ad.splash.AMPSSplashAd;
import xyz.adscope.amps.ad.splash.AMPSSplashLoadEventListener;
import xyz.adscope.amps.common.AMPSError;
import xyz.adscope.amps.config.AMPSRequestParameters;

public class SplashActivity extends BaseAdActivity {

    AMPSSplashAd ampsSplashAd;
    ConstraintLayout constraintLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        constraintLayout = findViewById(R.id.constraint_act_splash);
        loadAd();
    }

    @Override
    public void loadAd() {
        super.loadAd();
        AMPSRequestParameters parameter = new AMPSRequestParameters.Builder()
                .setSpaceId(Constants.JG_PUB_SPACE_ID_SPLASH)//插屏广告位Id
                .setTimeOut(Constants.JG_PUB_TIME_OUT)//超时时间
                .setWidth(600)//插屏广告宽度，单位px
                .setHeight(600)//插屏广告高度，单位px
                .build();
        ampsSplashAd = new AMPSSplashAd(this, parameter, new AMPSSplashLoadEventListener() {
            @Override
            public void onAmpsAdLoaded() {
                ampsSplashAd.show(constraintLayout);
            }

            @Override
            public void onAmpsAdFailed(AMPSError ampsError) {
            }

            @Override
            public void onAmpsAdShow() {
            }

            @Override
            public void onAmpsAdClicked() {
            }

            @Override
            public void onAmpsAdDismiss() {
                finish();
            }
        });
        ampsSplashAd.loadAd();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (ampsSplashAd != null) {
            ampsSplashAd.destroy();
            ampsSplashAd = null;
        }
    }
}